package com.gnerv.battle.boot.module.base.config;

import com.gnerv.battle.boot.module.base.interceptor.AuditApiMethodInterceptor;
import com.gnerv.battle.boot.module.base.service.AuditApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@EnableAsync
@Configuration
public class AuditLogConfig {

    private static final String REQUEST_MAPPING = "@annotation(org.springframework.web.bind.annotation.RequestMapping)";

    public DefaultPointcutAdvisor auditApiLogPointcutAdvisor(AuditApiService auditApiService) {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(REQUEST_MAPPING);
        DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut);
        defaultPointcutAdvisor.setAdvice(new AuditApiMethodInterceptor(auditApiService));
        return defaultPointcutAdvisor;
    }


}
